<?php
session_start;
require_once('include/connect.inc.php');
?>
<?php if(empty($_GET[action])){?>
<form name="form1" method="post" action="t.php?action=add">
  <p>จับคู่</p>
  <table width="513" border="1">
  <?php 
  $num=0;
  $count=0;
  $query3 = query("SELECT * FROM tb_set_detail where set_id=94 order by RAND()");
    	while ($rs3 = fetch_array($query3)) {
		$question_id3=$rs3['question_id'];
			  $query2= query("SELECT * FROM tb_question where question_id='".$question_id3." ' ");
			while ($rs2 = fetch_array($query2)) {
			$num++;
		?>
    <tr>
      <td width="456">ข้อที่[<?php echo $num;?>]<?php echo $count;?><?php echo $question_detail=$rs2['question_detail'];?>
      <input type="hidden" name="q_id[]" id="q_id[]" value="<?php echo $rs2[question_id]; ?>"></td>
      <td width="41">
      <select name="choice[<?php echo $count;?>]" id="choice[<?=$count?>]">
      	<option value="0">---เลือกคำตอบ---</option>
<?php
	$query33 = query("SELECT * FROM tb_set_detail where set_id=94");
    	while ($rs33 = fetch_array($query33)) {
		
$query2= query("SELECT * FROM tb_choice where answer>=2  and question_id='".$rs33[question_id]."' ");
		while ($rs2 = fetch_array($query2)) {
			$choice_detail=$rs2['choice_detail'];
			$choice_id=$rs2['choice_id'];
?>
        <option value="<?=$choice_id?>"><? echo $count;?><?=$choice_detail?></option>
        <?php
		}	
	}
?>
</select> 
</td>
    </tr>
 <?php } ?>
<?php  $count++;} ?>
  </table>
  <p>&nbsp;</p>
  <p>
    <input type="submit" name="button" id="button" value="Submit">
  </p>
</form>

<?php }
if($_GET[action]==add){

	for($i=0;$i<count($_POST[choice]);$i++){
	echo $q_id[$i].'   ';echo $choice[$i]; echo "<br>";
	$strSql="INSERT INTO tb_dotest_detail (choice_id,dotest_id,match_ans) VALUES ('".$choice[$i]."','66','".$q_id[$i]."')";
			$rs = execute($strSql);
	}
}
echo "Is been save..";
?>